<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="pc/include :: header('文档详情')" />
</head>
<body>
<th:block th:include="pc/include :: top" />
<link th:href="@{/css/context.css}" rel="stylesheet"/>
<style>
    .zub {
        margin-bottom: 30px;
    }
</style>
<div class="iw">
    <div class="crumbs">
        <p>当前位置：<a href="/">首页</a>
            <span th:if="${type}!=''" th:remove="tag"> > </span>
            <span th:utext="${type}" th:remove="tag"></span>
            <span th:if="${type}==''" th:remove="tag"> > </span> <span th:text="${sysdoc.title}" th:remove="tag"></span>
        </p>
    </div>
    <div class="view_left">
        <div class="view_title">
            <h1><i class="rb" th:classappend="${sysdoc.exten}" ></i> <span th:text="${sysdoc.title}" th:remove="tag"></span></h1>
            <ul class="view_title_info">
                <li class="li1"><a th:href="@{/user/center}"><i class="fa fa-user"></i><span th:text="${member.nickname}" th:remove="tag"></span></a></li>
                <li class="li2">
                    <span th:text="${sysdoc.readcount}" th:remove="tag"></span>次阅读</li>
                <li class="li3">
                    <span th:text="${sysdoc.downcount}" th:remove="tag"></span> 次下载</li>
                <li class="li4"><i class="fa fa-clock-o"></i>
                    <span th:text="${sysdoc.insertdate}" th:remove="tag"></span>
                </li>
            </ul>
            <ul class="view_title_menu">
                <li><a th:attr="modal-form=${report}">举报</a></li>
                <li> <i class="fa fa-heart fa-lg" th:classappend="${fav_state}?'active'"></i>收藏</li>
            </ul>
        </div>
        <div style="display: none" id="view-ad">
            <div class="view-ad" th:each="item :${sysAdvList}" th:if="${item.id}==6" >
                <a target="_blank" th:href="${item.page}"><img th:src="${item.src}" /></a>
            </div>
        </div>
        <div class="view_body">
            <i th:if="${sysdoc.isvip}" class="vip"><span>VIP免费</span></i>
        </div>
        <div th:if="${sysdoc.exten} !='mp4'" class="view_foot">
            <div class="nextread">
                <p>还剩<span>...</span> 页未读，<a>继续阅读</a></p><i></i>
            </div>
            <div class="payread">
                <h3>免费阅读已结束，点击付费阅读剩下 <span>...</span> 页</h3>
                <p><s th:if="${readpay2}!=${sysdoc.readpay}" th:text="|${systradesets.glodname}${sysdoc.readpay}${systradesets.glodunit}|"></s><span th:text="|${systradesets.glodname}${readpay2}${systradesets.glodunit}|"></span>，已有<span th:text="${sysdoc.readcount}"></span>人购买</p>
                <a th:classappend="${sysdoc.isvip}?'vip'" th:text="${readpay2}==0?'免费阅读': '付费阅读'"></a>
            </div>
            <div class="readover">
                <h3 th:if="${sysdoc.downpay} == null">阅读已结束，本文档禁止下载</h3>
                <h3 th:unless="${sysdoc.downpay == null}">阅读已结束，您可以下载文档离线阅读</h3>
                <p><s th:if="${downpay2}==${sysdoc.downpay}" th:text="|${systradesets.glodname}${sysdoc.readpay}${systradesets.glodunit}|"></s><span th:text="|${systradesets.glodname}${downpay2}${systradesets.glodunit}|"></span>，已有<span th:text="${sysdoc.downcount}"></span>人下载</p>
                <a th:classappend="${sysdoc.isvip}?'vip'" th:text="${downpay2}==0?'免费下载': '付费下载'"></a>
                <?php } ?>
            </div>
        </div>
        <div th:if="${sysdoc.exten} !='mp4'" class="view_short">
            <span>文档简介：</span>
            <h2 th:text="${sysdoc.word}"></h2>
        </div>
    </div>
    <div class="view_right">
        <div class="view_user">
            <a class="user-tip-p" th:href="@{'/user/doclist/'+${member.userid}}">
                <img th:src="${member.photo!=null} ? ${member.photo} : @{/img/photo.png}"   />
                <span th:text="${member.nickname}" th:remove="tag"></span>
            </a>
            <p>共<span th:text="${docnum}"></span>篇文档</p>
        </div>

        <div class="user_comment">
            <div>
                <h3>评论</h3>
                <textarea id="txt_comment" class="ui-text" placeholder="快来和小伙伴们说说吧"></textarea>
                <a class="csubmit" href="javascript:;">发表评论</a>
            </div>
            <ul>

                <li th:each="comment, userStat : ${comments}">
                    <div class="comment_head">
                        <img th:src="${comment.photo!=null} ? ${comment.photo} : @{/img/photo.png}" />
                        <a th:href="@{/user/center}" th:text="${comment.nickname}"></a>
                        <span th:text="${comment.insertdate}"></span>
                    </div>
                    <div class="comment_body" th:text="${comment.comment}">
                    </div>
                    <div class="comment_foot">
<!--
                        <a th:attr="data-id=${comment.commentid}" class="comment_up" th:classappend="${comment.state}==2?'active'"><i></i><span th:text="${comment.agree}" th:remove="tag"></span></a>
-->
                        <a th:if="${comment.isdel}" class="comment_del" th:attr="data-id=${comment.commentid}"><i>&times;</i></a>

                    </div>
                </li>
            </ul>
        </div>

    </div>
</div>
</div>
<div class="view_toolbar unselect">
    <div class="iw">
        <div class="view_left">
            <span class="full"></span>
            <span class="large"></span>
            <span class="small"></span>
            <span class="prev"><</span>
            <input class="cpage" type="text" value="1">
            <span class="pcount">/<span th:text="${hcount}" th:remove="tag"></span> </span>
            <span class="next">></span>

            <span th:if="${user.groupid} or ${sysdocset.anonypay}" class="download" th:classappend="${sysdoc.isvip}?'vip'"><i></i><span th:text="${downpay2}==0?'免费下载':'付费下载'" th:remove="tag"></span></span>
              <a th:unless="${user.groupid} or ${sysdocset.anonypay}" class="download2" th:classappend="${sysdoc.isvip}?'vip'" href="javascript:login_f()"><i></i><span th:text="${downpay2}==0?'免费下载':'付费下载'" th:remove="tag"></span></a>
              <span th:if="${downpay2}==${sysdoc.downpay}" th:text="|${systradesets.glodname}${downpay2}${systradesets.glodunit}|" class="downpay"></span>

            <span th:unless="${downpay2}==${sysdoc.downpay}" class="downpay"><s  th:text="|${systradesets.glodname}${sysdoc.downpay}${systradesets.glodunit}|"></s><div th:text="|${systradesets.glodname}${downpay2}${systradesets.glodunit}|" th:remove="tag"></div> </span>
            </div>


    </div>
</div>
</div>
<th:block th:include="pc/include :: footer" />
</html>
<script th:src="@{/js/context.js}"></script>
<script>
    $(".fa-heart").click(function () {
        if ([(${userid})] < 0) {
            login_ok = function () {
                location.href = location.href;
            }
            login_f();
        } else {
            $.get("doc/favorite/[(${sysdoc.docid})]", function (data) {
                if (data == -1) {
                    login_f();
                } else {
                    $(".fa-heart").toggleClass("active");
                }
            });
        }
    });

    $(".csubmit").click(function () {
        if ([(${userid})] < 0) {
            login_f();
        } else {
            var comment = $("#txt_comment").val();
            if (comment == "") {
                Message('请输入评论内容');
                return;
            }
            $.post("/doc/comment_submit", {
                comment: comment,
                docid: '[(${sysdoc.docid})]'
            }, function (data) {
                if(data.code==401) {
                    Message(data.msg,data.msg,function name()
                    {window.location.href="/login";});

                }
                if (data == 0) {
                    Message("评论已发布,审核后可查看.", "提示");
                } else if (data == 1) {
                    Message("评论已发布,刷新后查看.", "提示");
                } else {
                    Message("您没有发表评论的权限.", "提示");
                }
                $("#txt_comment").val('');
            });
        }
    });

    $(".comment_up").click(function () {
        if ([(${userid})] < 0) {
            login_f();
        } else {
            $this = $(this);
            $this.toggleClass("active");
            $.post("/doc/comment_agree/" + $(this).attr("data-id"), function (data) {
                if (data == -1) {
                    $this.toggleClass("active");
                    Message("您没有点评论权限", "提示");
                } else {
                    $this.html("<i></i>" + data);
                }
            });
        }
    });

    $(".comment_del").click(function () {
        if ([(${userid})] < 0) {
            login_f();
        } else {
            $this = $(this);
            console.log($(this).attr("data-id"));
            Dialog("确认删除评论?", "提示", function () {
                HideModal();
                $.post("/doc/comment_del", {
                    commentid: $this.attr("data-id")
                }, function (data) {
                    if (data == -1) {
                        Message("您没有删除评论权限", "提示");
                    } else {
                        $this.parent().parent().remove();
                    }
                });
            });
        }
    });
</script>
<script type="text/javascript">
    function embedload(e) {
        e.style.backgroundColor = '#fff';
    }

    var pcurrent = Number('[(${pcurrent})]');
    var psize = 5;
    var pshow = 0;
    var hcount = Number('[(${hcount})]');
    var preview= Number('[(${sysdoc.preview})]');
    var pcount = Number('[(${hcount})]');

    if ("[(${sysdoc.exten})]" == "mp4") {
        createvideo();
    } else {
        if (pcurrent > 1)
            gopage();
        else
            createpage(2);
    }

    function createvideo() {
        var video = '<video class="edui-upload-video" controlslist="nodownload" controls="" preload="none" width="900" src="down.doc.<?php echo $doc->docid; ?>.html" poster="doc-<?php echo $doc->docid; ?>.thum" ></video>';
        $(".view_body").append(video);
    }

    function createpage(size) {
        var much = size < preview - pshow ? size : preview - pshow;
        for (var i = 0; i < much; i++) {
            getpage(++pshow);
            if (pshow == hcount) {
                if('<?php echo $doc->downpay; ?>'===''){
                    if (pcount > hcount)
                        $(".readover h3").html("试读已结束，本文档禁止下载");
                    else
                        $(".readover h3").html("阅读已结束，本文档禁止下载");
                }else{
                    if (pcount > hcount)
                        $(".readover h3").html("试读已结束，您可以下载后继续阅读剩下的<span> " + (pcount - hcount) + " </span> 页");
                    else
                        $(".readover h3").html("阅读已结束，您可以下载文档离线阅读");
                }

                $(".view_foot div").hide();
                $(".readover").show();
                break;
            }
            if (pshow == preview) {
                $(".view_foot div").hide();
                $(".payread").show();
                $(".payread h3 span").text(hcount - pshow);
                break;
            }
            $(".view_foot div").hide();
            $(".nextread").show();
            $(".nextread span").text(hcount - pshow);
        }
    }

    function getpage(p) {
        var url = "page.htm?docid=[(${sysdoc.docid})]&page="+p;
        var page = '<div id="p' + p + '"><img onload="embedload(this)" alt="[(${sysdoc.title})]_第' + p + '页" title="[(${sysdoc.title})]_第' + p + '页" draggable="false" src="' + url + '" /></div>';
        $(".view_body").append(page);
        var $ad = $(".view-ad").html();
        if ($ad) {
            $(".view_body").append($ad);
        }
    }

    $(".nextread a,.nextread img").click(function () {
        createpage(psize);
    });

    $(".payread a").click(function () {
        if ('[(${readpay2})]' == '0') {
            payread();
        } else {
            $.get("readpay.htm?docid=[(${sysdoc.docid})]&readpay=[(${sysdoc.readpay})]&readpay2=[(${readpay2})]&type=doc&readdown=readpay", function (html) {
                Dialog2(html);
            });
        }
    });

    $(".readover a,.download").click(function () {
        if ('[(${downpay2})]' == '0') {
            paydown();
        } else {
            $.get("readpay.htm?docid=[(${sysdoc.docid})]&readpay=[(${sysdoc.downpay})]&readpay2=[(${downpay2})]&type=doc&readdown=downpay", function (html) {
                Dialog2(html);
            });
        }
    });

    if (window.location.hash === "#readpay") {
        payread();
    }
    if (window.location.hash === "#downpay") {
        paydown();
    }

    var login_ok;
    function payread() {
        $.get("/doc/payread/[(${sysdoc.docid})]", function (data) {
            if (data > 0) {
                preview = hcount;
                createpage(psize);
            } else if (data == -11) {
                login_ok = function () {
                    payread();
                }
                login_f();
            } else if (data == -13) {
                Message("您没有阅读权限。", "提示");
            } else if (data == -14) {
                Message("今天阅读次数已超，请明天再来下载。", "提示");
            } else if (data == -1) {
                Dialog("积分不足，去充值？", "提示", function () {
                    location = "/user/glodpay";
                });
            } else if (data == -12) {
                Message("文档不存在。", "提示");
            } else {
                //出错了
            }
        });
    }

    function paydown() {
        $.post("/doc/paydown/[(${sysdoc.docid})]", function (data) {
            if (data > 0) {
                location.href = "/downdoc.htm?docid=[(${sysdoc.docid})]";
            } else if (data == -11) {
                login_ok = function () {
                    paydown();
                }
                login_f();
            } else if (data == -13) {
                Message("您没有下载权限。", "提示");
            } else if (data == -14) {
                Message("今天下载数量已超，请明天再来下载。", "提示");
            } else if (data == -1) {
                Dialog("积分不足，去充值？", "提示", function () {
                    location = "/user/glodpay";
                });
            } else if (data == -12) {
                Message("文档不存在。", "提示");
            } else {
                //出错了
            }
        });
    }

    $(".view_toolbar .prev").click(function () {
        if (pcurrent > 1) {
            pcurrent--;
            gopage();
        }
    });
    $(".view_toolbar .next").click(function () {
        if (pcurrent < preview) {
            pcurrent++;
            gopage();
        }
    });
    $(".view_toolbar .cpage").change(function () {
        var p = parseInt($(this).val());
        if (isNaN(p)) {
            // do nothing
        } else if (p < 1) {
            pcurrent = 1;
        } else if (p > preview) {
            pcurrent = preview;
        } else {
            pcurrent = p;
        }
        gopage();
    });

    function gopage() {
        if (pcurrent > pshow) {
            createpage(pcurrent - pshow + 5);
        }
        location.hash = "p" + pcurrent;
    }

    function getdocheight() {
        return $("#p1").height();
    }
    $(window).scroll(function () {
        var top = $(window).scrollTop();
        var fix = $(".view_body").offset().top;
        var advdoc = (getdocheight() + 126) * Number('2');
        if (top - fix < advdoc) {
            var pcu = (top - fix) / (getdocheight() + 126);
        } else {
            var pcu = (top - fix - advdoc) / (getdocheight() + 12) + Number('2');
        }

        pcurrent = Math.round(pcu) + 1;
        if (pcurrent > pshow)
            pcurrent = pshow;
        if (pcurrent < 1) {
            pcurrent = 1;
        }
        $(".view_toolbar .cpage").val(pcurrent);
    });

    var doc_width = 900;
    $(".view_toolbar .small").click(function () {
        if (doc_width > 700) {
            doc_width -= 100;
            Scale();
        }
    });
    $(".view_toolbar .large").click(function () {
        if (doc_width < 1200) {
            doc_width += 100;
            Scale();
        }
    });
    $(".view_toolbar .full").click(function () {
        if (doc_width >= 1200) {
            doc_width = 900;
        } else {
            doc_width = 1200;
        }
        Scale();
    });

    function Scale() {
        $(".view_left").css({
            "width": doc_width
        });
        if (doc_width > 900) {
            $(".view_right").hide();
        } else {
            $(".view_right").show();
        }
    }


    context.init({
        preventDoubleContext: false
    });
    context.settings({
        compress: true
    });
    context.attach('.view_body img', [{
        text: '上一页',
        action: function (e) {
            e.preventDefault();
            $(".view_toolbar .prev").trigger("click");
        }
    },
        {
            text: '下一页',
            action: function (e) {
                e.preventDefault();
                $(".view_toolbar .next").trigger("click");
            }
        },
        {
            text: '下载',
            action: function (e) {
                e.preventDefault();
                $(".readover a,.download").trigger("click");
            }
        },
        {
            text: '刷新',
            action: function (e) {
                e.preventDefault();
                location.reload();
            }
        },
        {
            text: '后退',
            action: function (e) {
                e.preventDefault();
                window.history.go(-1);
            }
        }
    ]);
    $(document).on('mouseover', '.me-codesta', function () {
        $('.finale h1:first').css({
            opacity: 0
        });
        $('.finale h1:last').css({
            opacity: 1
        });
    });
    $(document).on('mouseout', '.me-codesta', function () {
        $('.finale h1:last').css({
            opacity: 0
        });
        $('.finale h1:first').css({
            opacity: 1
        });
    });


    $(".view_shang > span").click(function () {
        if ($(".view_shang > div").css("display") == "none")
            $(".view_shang > div").css("display", "inline-block");
        else
            $(".view_shang > div").css("display", "none");
    });

    $('.edui-upload-video').bind('contextmenu', function () { return false; });
</script>
